<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="Categories.aspx.cs" Inherits="Admin_Risk_Categories" Title="APM - Risk Impact Assessment" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="assessment">
        <ul id="path">
            <li><a href="../../Home.aspx">Home</a> &gt;</li>
            <li>Administration &gt;</li>
            <li>Risk Impact Assessment</li>
        </ul>
        <h3 class="assessment"><span>Manage Question Categories</span></h3>
        <div id="content">
            <p>
            </p>
            <table width="100%">
                <tr>
                    <td align="left" colspan="2" style="font-weight: bold; height: 25px; vertical-align: top">
                        Add new Category
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <table cellpadding="0" cellspacing="0" border="0">
                            <tr>
                                <td style="width: 91px;">
                                    Category Name
                                </td>
                                <td>
                                    <table cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td>
                                                <asp:TextBox runat="server" ID="txtCatName" Width="100" MaxLength="50" CssClass="input"></asp:TextBox>
                                            </td>
                                            <td>
                                                &nbsp;&nbsp;Example - Architecture
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:Button runat="server" ID="btnSave" Text="Submit" ToolTip="Click to add new Category"
                            ValidationGroup="Add" CausesValidation="true" OnClick="Category_Add" />
                        <asp:ValidationSummary runat="server" HeaderText="Please correct the following:"
                            ShowMessageBox="true" ValidationGroup="Add" ID="valiAllValidations" ShowSummary="false"
                            DisplayMode="BulletList" />
                        <asp:RequiredFieldValidator ID="reqName" runat="server" SetFocusOnError="true" Display="None"
                            ValidationGroup="Add" ControlToValidate="txtCatName" ErrorMessage=" Required Field: Category Name "></asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator ID="regexName" runat="server" ControlToValidate="txtCatName"
                            ErrorMessage="Invalid Input: Category Name " ValidationGroup="Add" ValidationExpression="<%$ AppSettings:CatNameRegEx %>"
                            Display="None" SetFocusOnError="true"></asp:RegularExpressionValidator>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        Existing Categories
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                    <asp:GridView ID="gridCategory" runat="server" AllowPaging="True" AllowSorting="True"
                            DataSourceID="obdsCategory" AutoGenerateColumns="False" AutoGenerateEditButton="False"
                            CssClass="table" DataKeyNames="QuestionCategoryID" OnRowDeleted="gridCategory_RowDeleted"
                            EmptyDataText="No staging categories found." OnRowUpdated="gridCategory_RowUpdated"
                            OnRowDataBound="gridCategory_RowDataBound"
                            PageSize="10">
                            <AlternatingRowStyle CssClass="alternate" />
                            <PagerSettings Position="TopAndBottom" />
                            <PagerStyle CssClass="pages" />
                            <EmptyDataRowStyle BackColor="#C4D7D6" BorderStyle="none" />
                            <HeaderStyle HorizontalAlign="Left" />
                            <Columns>
                                <asp:CommandField ValidationGroup="Update" ShowCancelButton="true" ShowDeleteButton="true"
                                    DeleteText="Delete" ShowEditButton="true" HeaderText="Select" ButtonType="link"
                                    CausesValidation="true" HeaderStyle-HorizontalAlign="left" ItemStyle-HorizontalAlign="left">
                                    <ItemStyle Width="110px" Wrap="False" />
                                </asp:CommandField>
                                <asp:TemplateField HeaderText="Category" SortExpression="ContactType">
                                    <ItemTemplate>
                                        <a href="Questions.aspx?ID=<%# Microsoft.Security.Application.AntiXss.HtmlEncode(Eval("QuestionCategoryID").ToString()) %>">
                                            <%# Microsoft.Security.Application.AntiXss.HtmlEncode(Eval("CategoryName").ToString()) %>
                                        </a>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:TextBox ID="txtCategoryName" Height="17" runat="Server" Text='<%# Bind("CategoryName") %>'
                                            MaxLength="50" Width="100" CssClass="input" />
                                        <asp:RequiredFieldValidator ID="reqCatName" runat="server" ControlToValidate="txtCategoryName"
                                            ErrorMessage="Required Field: Category Name" Display="None" SetFocusOnError="True"
                                            ValidationGroup="Update"></asp:RequiredFieldValidator>
                                        <asp:RegularExpressionValidator ID="regexCatName" runat="server" ControlToValidate="txtCategoryName"
                                            ErrorMessage="Invalid Input: Category Name" ValidationExpression="<%$ AppSettings:CatNameRegEx %>"
                                            Display="None" ValidationGroup="Update"></asp:RegularExpressionValidator>
                                    </EditItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <RowStyle HorizontalAlign="Left" />
                        </asp:GridView>
                        <asp:ValidationSummary ID="vsCategory" runat="server" HeaderText="Please correct the following:"
                            ShowMessageBox="true" ShowSummary="false" DisplayMode="BulletList" ValidationGroup="Update" />
                        <asp:ObjectDataSource ID="obdsCategory" UpdateMethod="UpdateCategory"
                            runat="server" TypeName="Microsoft.AceEngineering.SPM.SPMBusinessLayer.CategoryBL"
                            SelectMethod="GetCategory" OldValuesParameterFormatString="{0}" SortParameterName="dir"
                            DeleteMethod="DeleteCategory">
                            <DeleteParameters>
                                <asp:Parameter Name="QuestionCategoryID" Type="String" />
                            </DeleteParameters>
                            <UpdateParameters>
                                <asp:Parameter Name="QuestionCategoryID" Type="String" />
                                <asp:Parameter Name="CategoryName" Type="String" />
                                <asp:SessionParameter Name="CreatedBy" SessionField="loginname" Type="String" />
                            </UpdateParameters>
                        </asp:ObjectDataSource>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        &nbsp;</td>
                </tr>
                <tr>
                    <td colspan="2">
                        <font style="font-weight: bold">Staging Status: </font><font style="color: Red">
                            <asp:Label ID="lblMsg3" runat="server"></asp:Label></font>
                        <asp:Panel runat="server" ID="pnlError" Visible="false">
                            <font style="font-weight: bold">Status Details: </font><font style="color: Red">
                                <asp:Label ID="lblMsg" runat="server"></asp:Label></font>
                        </asp:Panel>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="CreateStagingDB"
                            OnClick="CreateStagingDB" 
                            Text="Load Staging" />
                        <asp:Button ID="btnPreview" runat="server" CausesValidation="false" CommandName="Preview"
                            OnClick="PreviewStaging" Text="Preview Staging" />
                        <asp:Button ID="btnPublish" runat="server" CausesValidation="false" CommandName="Publish"
                            OnClick="PublishStaging" Text="Publish Staging"  />
                    </td>
                </tr>
            </table>
        </div>
    </div>
</asp:Content>
